package com.tuanzi.loan.business.repository.statistics.impl;

import com.tuanzi.loan.business.repository.statistics.CreditCardManagerDataStatRepository;
import com.tuanzi.loan.core.repository.JOOQBaseRepositoryPlus;
import com.tuanzi.loan.vo.request.statistics.CreditCardManagerDataStatSearchRequest;
import com.tuanzi.loan.vo.response.statistics.CreditCardManagerDataStatSearchResponse;
import com.tuanzi.server.loan_base.util.DateUtils;
import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.Objects;

import static com.tuanzi.loan.generated.jooq.stat.Tables.CREDIT_CARD_MANAGER_SYNTHETIC_DATA;

@Repository
public class CreditCardManagerDataStatRepositoryImpl extends JOOQBaseRepositoryPlus implements CreditCardManagerDataStatRepository{
    @Override
    public Page<CreditCardManagerDataStatSearchResponse> getList(CreditCardManagerDataStatSearchRequest searchRequest, Pageable pageable) {
        fields();
        if (Objects.nonNull(searchRequest.getStartDate())){
            ge(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.TIME, DateUtils.formatDateToYyyyMMdd(searchRequest.getStartDate()));
        }
        if (Objects.nonNull(searchRequest.getEndDate())){
            le(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.TIME,DateUtils.formatDateToYyyyMMdd(searchRequest.getEndDate()));
        }
        return search(pageable,record -> {
            CreditCardManagerDataStatSearchResponse response = new CreditCardManagerDataStatSearchResponse();
            response.setAdd(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.ADD));
            response.setAdd_bind_card_count(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.ADD_BIND_CARD_COUNT));
            response.setId(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.ID));
            response.setTime(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.TIME));
            response.setSuccess_order_count(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.SUCCESS_ORDER_COUNT));
            response.setParticipation_uv_than_day_live(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.PARTICIPATION_UV_THAN_DAY_LIVE));
            response.setOrder_success_rate(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.ORDER_SUCCESS_RATE));
            response.setOrder_count(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.ORDER_COUNT));
            response.setOpen_card_index_uv(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.OPEN_CARD_INDEX_UV));
            response.setDetail_uv(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.DETAIL_UV));
            response.setDay_live(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.DAY_LIVE));
            response.setDaichao_index_uv(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.DAICHAO_INDEX_UV));
            response.setCompensation_index_uv(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.COMPENSATION_INDEX_UV));
            response.setClick_list_uv(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.CLICK_LIST_UV));
            response.setBind_card_count(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.BIND_CARD_COUNT));
            response.setAdd_rate(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.ADD_RATE));
            response.setAdd_bind_card_rate(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.ADD_BIND_CARD_RATE));
            response.setParticipation_uv(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.PARTICIPATION_UV));
            response.setBind_day_live(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.BIND_DAY_LIVE));
            response.setNo_bind_day_live(record.get(CREDIT_CARD_MANAGER_SYNTHETIC_DATA.NO_BIND_DAY_LIVE));
            return response;
        });
    }

    @Override
    protected TableImpl getTable() {
        return CREDIT_CARD_MANAGER_SYNTHETIC_DATA;
    }
}
